package cc.linker.steplink.crm.merchanth5.service;

import cc.linker.steplink.crm.commons.utils.NumberUtils;
import cc.linker.steplink.crm.merchanth5.dao.RecommendDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

@Service
public class RecommendService {
    @Autowired
    private RecommendDao recommendDao;


    public Map<String,Object> info(String customerId)
    {
        Map<String,Object> param = new HashMap<>();
        Map<String,Object> result = new HashMap<>();

        param.put("customerId",customerId);
        //累计
        Map<String,Object> all = recommendDao.info(param);
        all.put("customerNum",recommendDao.getCustomerNum(param));
        all.put("total", NumberUtils.fenToYuan(Long.parseLong(all.get("total").toString())));
        //今日
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //今日开始时间
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        //今日结束时间
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        param.put("startTime",sdf.format(todayStart.getTime()));
        param.put("endTime",sdf.format(todayEnd.getTime()));
        Map<String,Object> day = recommendDao.info(param);
        day.put("customerNum",recommendDao.getCustomerNum(param));
        day.put("total", NumberUtils.fenToYuan(Long.parseLong(day.get("total").toString())));

        Long customerBalance = recommendDao.getCustomerBalance(customerId);
        result.put("customerBalance",NumberUtils.fenToYuan(customerBalance));
        result.put("all",all);
        result.put("day",day);
        return result;
    }
}
